package com.roncoo.education.course.service.api.auth.biz;

import com.roncoo.education.course.service.dao.CourseChapterDao;
import com.roncoo.education.course.service.dao.CourseChapterPeriodDao;
import com.roncoo.education.course.service.dao.CourseDao;
import com.roncoo.education.course.service.dao.impl.mapper.entity.Course;
import com.roncoo.education.course.service.dao.impl.mapper.entity.CourseChapter;
import com.roncoo.education.course.service.dao.impl.mapper.entity.CourseChapterPeriod;
import com.roncoo.education.util.base.Result;
import com.xiaoleilu.hutool.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class AuthApiCourseComponent {
    @Autowired
    private CourseDao courseDao;
    @Autowired
    private CourseChapterDao courseChapterDao;
    @Autowired
    private CourseChapterPeriodDao courseChapterPeriodDao;

    public Result check(Long courseId,Long chapterId,Long periodId){
        // 课时信息
        CourseChapterPeriod courseChapterPeriod = courseChapterPeriodDao.getById(periodId);
        if (StringUtils.isEmpty(courseChapterPeriod)) {
            return Result.error("找不到课时信息");
        }
        // 章节信息
        CourseChapter courseChapter = courseChapterDao.getById(chapterId);
        if (ObjectUtil.isNull(courseChapter)) {
            return Result.error("找不到章节信息");
        }
        // 课程信息
        Course course = courseDao.getById(courseId);
        if (StringUtils.isEmpty(course)) {
            return Result.error("找不到课程信息");
        }
        return null;
    }

    public Result check(Long courseId,Long chapterId){
        // 课时信息
//        CourseChapterPeriod courseChapterPeriod = courseChapterPeriodDao.getById(periodId);
//        if (StringUtils.isEmpty(courseChapterPeriod)) {
//            return Result.error("找不到课时信息");
//        }
        // 章节信息
        CourseChapter courseChapter = courseChapterDao.getById(chapterId);
        if (ObjectUtil.isNull(courseChapter)) {
            return Result.error("找不到章节信息");
        }
        // 课程信息
        Course course = courseDao.getById(courseId);
        if (StringUtils.isEmpty(course)) {
            return Result.error("找不到课程信息");
        }
        return null;
    }
}
